<template>
	<view class="wrap">
		<view class="top">
			<view class="item">
				<view class="left">姓名</view>
				<input type="text" v-model="a1" placeholder-class="line" placeholder="请填写姓名" />
			</view>
			<view class="item">
				<view class="left">性别</view>
				<radio-group @change="sexx">
					<radio value="女" :checked="sex==1">女</radio>
					<radio value="男" :checked="sex==0">男</radio>
				</radio-group>
			</view>
			<view class="item">
				<view class="left">手机号码</view>
				<input type="text" v-model="a2" placeholder-class="line" placeholder="请填写手机号" />
			</view>
			<view class="item">
				<view class="left">身份证号</view>
				<input type="text" v-model="a3" placeholder-class="line" placeholder="请填写手机号" />
			</view>
			<view class="item">
				<view class="left">出生日期</view>
				<picker mode="date" v-model="a4" :value="value" @change="chang">{{this.a4== ''?'点击选择出生日期':this.a4}}
				</picker>
			</view>

			<view class="item address">
				<view class="left">所在地址地址</view>
				<textarea type="text" v-model="a6" placeholder-class="line" placeholder="街道、楼牌等" />
			</view>
			</br>
			<button @click="xijian">{{type == 1?'新建就诊人':'修改就诊人'}}</button>
		</view>

		<u-picker mode="region" ref="uPicker" v-model="show" @confirm="chang2" />
	</view>
</template>

<script>
	import api from '../../../../commer/apiURL.js'
	export default {
		data() {
			return {
				base: api.baseurl,
				show: false,
				value: '',
				type: '',
				card: '',
				a1: '',
				a2: '',
				a3: '',
				a4: '',
				a6: '',
				sex: 0,
				jiuzhenid: ''
			};
		},
		onLoad(options) {
			this.type = options.type
			if (options.type == 1) {
				uni.setNavigationBarTitle({
					title: "新建就诊人"
				})
			} else {
				uni.setNavigationBarTitle({
					title: "修改就诊人"
				})
				this.getxiu()
			}

		},
		methods: {
			xijian() {
				if (this.type == 1) {
					//新建
					this.$post(this.base + '/prod-api/api/hospital/patient', {
						"address": this.a6,
						"birthday": this.a4,
						"cardId": this.a3,
						"name": this.a1,
						"sex": this.sex,
						"tel": this.a2
					}).then((res) => {
						if (res.code == 200) {
							uni.showToast({
								title: '新建成功'
							})
							setTimeout(()=>{
								uni.navigateTo({
									url:'renjiu'
								})
							},500)
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
				} else {
					this.$put(this.base + '/prod-api/api/hospital/patient', {
						"id": this.jiuzhenid,
						"address": this.a6,
						"birthday": this.a4,
						"cardId": this.a3,
						"name": this.a1,
						"sex": this.sex,
						"tel": this.a2
					}).then((res) => {
						if (res.code == 200) {
							uni.showToast({
								title: '修改成功'
							})
							setTimeout(()=>{
								uni.navigateTo({
									url:'renjiu'
								})
							},500)
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
				}
			},
			sexx(e) {
				this.sex = e.detail.value == '女' ? 1 : 0
			},
			chang(e) {
				this.a4 = e.detail.value
			},
			getxiu() {
				let card = uni.getStorageSync('jiuzhenCrd')
				this.a1 = card.name
				this.a2 = card.tel
				this.a3 = card.cardId
				this.a4 = card.birthday
				this.a6 = card.address
				this.sex = card.sex
				this.jiuzhenid = card.id

				// this.a1 = card.
			},
			setDefault() {},
			showRegionPicker() {
				this.show = true;
			}
		}
	};
</script>

<style lang="scss" scoped>
	/deep/ .line {
		color: $u-light-color;
		font-size: 28rpx;
	}

	.wrap {
		background-color: #f2f2f2;

		.top {
			background-color: #ffffff;
			border-top: solid 2rpx $u-border-color;
			padding: 22rpx;

			.item {
				display: flex;
				font-size: 32rpx;
				line-height: 100rpx;
				align-items: center;
				border-bottom: solid 2rpx $u-border-color;

				.left {
					width: 180rpx;
				}

				input {
					text-align: left;
				}
			}

			.address {
				padding: 20rpx 0;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}
			}

			.site-clipboard {
				padding-right: 40rpx;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}

				.clipboard {
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: $u-tips-color;
					height: 80rpx;

					.icon {
						margin-top: 6rpx;
						margin-left: 10rpx;
					}
				}
			}
		}

		.bottom {
			margin-top: 20rpx;
			padding: 40rpx;
			padding-right: 0;
			background-color: #ffffff;
			font-size: 28rpx;

			.tag {
				display: flex;

				.left {
					width: 160rpx;
				}

				.right {
					display: flex;
					flex-wrap: wrap;

					.tags {
						width: 140rpx;
						padding: 16rpx 8rpx;
						border: solid 2rpx $u-border-color;
						text-align: center;
						border-radius: 50rpx;
						margin: 0 10rpx 20rpx;
						display: flex;
						font-size: 28rpx;
						align-items: center;
						justify-content: center;
						color: $u-content-color;
						line-height: 1;
					}

					.plus {
						//padding: 10rpx 0;
					}
				}
			}

			.default {
				margin-top: 50rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: solid 2rpx $u-border-color;
				line-height: 64rpx;

				.tips {
					font-size: 24rpx;
				}

				.right {}
			}
		}
	}
</style>
